package com.yang.booking.controller;

import com.yang.booking.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Map;

@RestController
public class AppointmentController {

    @Autowired
    private AppointmentService appointmentService;

    @PostMapping("/provider/appointment/insertAppointment")
    public Map<String, Object> insertAppointment(@RequestParam(name = "storeId") String storeId,
                                                 @RequestParam(name = "type") String type,
                                                    @RequestParam(name = "userType") String userType,
                                                    @RequestParam(name = "userName") String userName,
                                                    @RequestParam(name = "userId") String userId,
                                                    @RequestParam(name = "source") String source,
                                                    @RequestParam(name = "appType") String appType,
                                                    @RequestParam(name = "beauticianId") String beauticianId,
                                                    @RequestParam(name = "beauticianName") String beauticianName,
                                                    @RequestParam(name = "arrivalDate") String arrivalDate,
                                                    @RequestParam(name = "phone") String phone,
                                                    @RequestParam(name = "itemId") String itemId,
                                                    @RequestParam(name = "itemName") String itemName,
                                                    @RequestParam(name = "consumTime") String consumTime,
                                                    @RequestParam(name = "roomId") String roomId,
                                                    @RequestParam(name = "roomName") String roomName,
                                                    @RequestParam(name = "serviceStartTime") String serviceStartTime,
                                                    @RequestParam(name = "serviceEndTime") String serviceEndTime,
                                                    @RequestParam(name = "remarks") String remarks,
                                                    @RequestParam(name = "temporaryArrangeId") String temporaryArrangeId,
                                                    @RequestParam(name = "id") String id,
                                                    @RequestParam(name = "iu") String iu
    ) throws ParseException {

        return appointmentService.insertAppointment(storeId, Integer.parseInt(type), Integer.parseInt(userType), userId, userName, Integer.parseInt(source), Integer.parseInt(appType),
                beauticianId, beauticianName, arrivalDate, phone, itemId, itemName, consumTime, roomId, roomName,
                serviceStartTime, serviceEndTime, remarks, temporaryArrangeId, id, iu);
    }

    @PostMapping("/provider/appointment/queryAppointmentAll")
    public Map<String, Object> queryAppointmentAll(@RequestParam(name = "storeId") String storeId,
                                                    @RequestParam(name = "serviceStartTime") String serviceStartTime,
                                                    @RequestParam(name = "serviceEndTime") String serviceEndTime,
                                                    @RequestParam(name = "userNameOrPhone") String userNameOrPhone,
                                                    @RequestParam(name = "source") String source,
                                                    @RequestParam(name = "appType") String appType,
                                                    @RequestParam(name = "beauticianId") String beauticianId,
                                                    @RequestParam(name = "state") String state,
                                                    @RequestParam(name = "pageSize") String pageSize,
                                                    @RequestParam(name = "pageNo") String pageNo
    ){
        return appointmentService.queryAppointmentAll(storeId, serviceStartTime, serviceEndTime, userNameOrPhone, source, appType, state, beauticianId, pageSize, pageNo);
    }

    @PostMapping("/provider/appointment/cancleAppointment")
    public Map<String, Object> cancleAppointment(@RequestParam(name = "storeId") String storeId,
                                                   @RequestParam(name = "appointmentId") String appointmentId
    ){
        return appointmentService.cancleAppointment(storeId, appointmentId);
    }

    @PostMapping("/provider/appointment/appointmentStatistics")
    public Map<String, Object> appointmentStatistics(@RequestParam(name = "storeId") String storeId,
                                                 @RequestParam(name = "regionId") String regionId,
                                                     @RequestParam(name = "startTime") String startTime,
                                                     @RequestParam(name = "endTime") String endTime
    ) throws ParseException {
        return appointmentService.appointmentStatistics(storeId, regionId, startTime, endTime);
    }

    @PostMapping("/provider/appointment/queryUserAppointment")
    public Map<String, Object> queryUserAppointment(@RequestParam(name = "userId") String userId,
                                                     @RequestParam(name = "state") String state,
                                                     @RequestParam(name = "pageSize") String pageSize,
                                                     @RequestParam(name = "pageNo") String pageNo
    ) throws ParseException {
        return appointmentService.queryUserAppointment(userId, state, pageSize, pageNo);
}
}
